package com.dragons.spring5_reactor.webflux_reactor;

import org.springframework.web.cors.reactive.CorsUtils;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class FluxAndMono {
    public static void main(String[] args) {
        //just 方法直接声明
        Flux.just(1,2,3,4).subscribe(System.out::print); // 发送元素
        Mono.just(1).subscribe(System.out::print);


        //其他的方法
        Integer[] array = {1,2,3,4};
        Flux.fromArray(array);
        List<Integer> list = Arrays.asList(array);
        Flux.fromIterable(list);
        Stream<Integer> stream = list.stream();
        Flux.fromStream(stream);
    }


//    public Mono<Void> handle(ServerWebExchange exchange) { //放http请求响应信息
//        if (this.handlerMappings == null) {
//            return this.createNotFoundError();
//        } else {
//            return CorsUtils.isPreFlightRequest(exchange.getRequest()) ?
//                    this.handlePreFlight(exchange)
//                    :
//                    Flux.fromIterable(this.handlerMappings).concatMap((mapping) -> {
//                return mapping.getHandler(exchange); //根据请求地址获取对应mapping
//            }).next().switchIfEmpty(this.createNotFoundError()).flatMap((handler) -> {
//                return this.invokeHandler(exchange, handler); //调用具体的业务方法
//            }).flatMap((result) -> {
//                return this.handleResult(exchange, result);//处理结果返回
//            });
//        }
//    }
}



